package com.my.study.init.log;

import cn.hutool.core.lang.UUID;
import lombok.Data;
import org.slf4j.MDC;

/**
 * 通过自定义filter中调用当前方法将值设置进去
 */
@Data
public class LogContext {

    private static final String USER_ID = "USER_ID";
    private static final String TRACE_ID = "TRACE_ID";

    public String createTranceId(){
        return UUID.randomUUID().toString();
    }

    public void setTraceId(LogInfo logInfo){
        MDC.put(USER_ID,logInfo.getUserId());
        MDC.put(TRACE_ID,logInfo.getTraceId());
    }

    public void getTraceId(String traceId){
        MDC.get(traceId);
    }
}
